package com.letv.whatslive.model.convert;

import com.letv.whatslive.common.utils.ObjectUtils;
import com.letv.whatslive.model.SdkTable;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by 55 on 2016/5/23.
 */
public class SdkTableConvert {
    public static DBObject castSdkTableToDBObject(SdkTable sdkTable) {

        DBObject dbo = new BasicDBObject();

        dbo.put("_id", ObjUtils.toLong(sdkTable.getId()));
        dbo.put("appId", ObjUtils.toLong(sdkTable.getAppId()));
        dbo.put("sdkName", ObjUtils.toString(sdkTable.getSdkName()));
        dbo.put("createTime", ObjUtils.toString(sdkTable.getCreateTime()));

        return dbo;
    }

    public static SdkTable castDBObjectToSdkTable(DBObject dbObject){

        if(dbObject != null) {
            SdkTable SdkTable = new SdkTable();
            SdkTable.setId(ObjectUtils.toLong(dbObject.get("_id")));
            SdkTable.setCreateTime(ObjectUtils.toString(dbObject.get("createTime")));
            SdkTable.setAppId(ObjUtils.toLong(dbObject.get("appId")));
            SdkTable.setSdkName(ObjUtils.toString(dbObject.get("sdkName")));
            return SdkTable;
        }else{
            return null;
        }
    }
}
